# Set working directory
setwd("C:/Users/Eric/Dropbox/NSC Group Decisionmaking/Analysis/io_replication/")


# Stargazer package may not work properly in default installation.
# Long model names may cause issues.
# Run this code just once to re-install stargazer.

# This code below is entirely from: https://gist.github.com/alexeyknorre/b0780836f4cec04d41a863a683f91b53

# Unload stargazer if loaded
detach("package:stargazer",unload=T)

# Delete it
remove.packages("stargazer")

# Download the source
download.file("https://cran.r-project.org/src/contrib/stargazer_5.2.3.tar.gz", destfile = "stargazer_5.2.3.tar.gz")

# Unpack source
untar("stargazer_5.2.3.tar.gz")

# Read the sourcefile with .inside.bracket fun
stargazer_src <- readLines("stargazer/R/stargazer-internal.R")

# Move the length check 5 lines up so it precedes is.na(.)
stargazer_src[1990] <- stargazer_src[1995]
stargazer_src[1995] <- ""

# Save back
writeLines(stargazer_src, con="stargazer/R/stargazer-internal.R")

# Compile and install the patched package
install.packages("stargazer", repos = NULL, type="source")
